<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>有一组文本框，要求让每一个文本框在自己输入的时候，背景显示灰色，其他文本框显示白色。</title>
    <style>
        #user {
            display: flex;
            flex-direction: column;
        }
        #user>a {
            color: black;
            text-decoration: none;
            display: inline-flex;
        }
        #user>a>input[name] {
            outline: none;
        }
    </style>
</head>
<body>
    <form id="user" action="" method="get">
        <a href="javascript:void(0)">姓名:<input type="text" name="user_name"></a>
        <a href="javascript:void(0)">年龄:<input type="text" name="age"></a>
        <a href="javascript:void(0)">性别:<input type="text" name="sex"></a>
        <a href="javascript:void(0)">生日:<input type="text" name="birthday"></a>
        <a href="javascript:void(0)">爱好:<input type="text" name="habbily"></a>   
    </form>
    <script>
        let user = document.getElementById("user");
        let user_form = document.querySelectorAll("#user>a>input[name]");
        console.dir(user_form);
        user.onclick = function(e){
            e = e||window.event;
            let input = e.target;
            for(let i = 0;i<user_form.length;i++){
                user_form[i].style.backgroundColor = "white";
            }
            console.log(e);
            if(e.target.name){
                input.style.backgroundColor = "#c0c0c0";
            }
            
        };
    </script>
</body>
</html>